package com.gxa.weixing.pc.controller;

import com.gxa.weixing.core.common.ExceptionCode;
import com.gxa.weixing.core.common.JsonResult;
import com.gxa.weixing.core.exception.BusinessException;
import com.gxa.weixing.core.pojo.GoldRun;
import com.gxa.weixing.core.util.StringUtil;
import com.gxa.weixing.pc.service.GoldRunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author ChenJ
 * @date 2022/01/06 16:05
 **/
@RestController
@Api(value = "goldRunController",tags = "运营策略配置相关接口")
@RequestMapping("/goldRun")
public class GoldRunController {

    @Resource
    private GoldRunService goldRunService;

    @PostMapping("/save")
    @ApiOperation("修改运营策略配置接口")
    @ApiImplicitParam(name = "goldRun", value = "运营策略模板对象",dataType = "GoldRun", paramType = "body",dataTypeClass = GoldRun.class)
    public Map<String ,Object> save(@RequestBody GoldRun goldRun) throws BusinessException {
        System.out.println(goldRun+"----------------------------------------------------");
        if (goldRun==null){
            throw new BusinessException(ExceptionCode.NO_PARAM);
        }
        if(!StringUtil.isPhoneNumber(goldRun.getIosTmk())){
            throw new BusinessException(ExceptionCode.WRONG_PHONE);
        }
        Integer integer = goldRunService.updateById(goldRun);
        if (integer == 0){
            throw new BusinessException(ExceptionCode.WRONG_UPDATE);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功成功");
        return jsonResult.getDataMap();
    }

    @GetMapping("/getGoldRun")
    @ApiOperation("获取运营策略配置")public Map<String ,Object> getGoldRun() throws BusinessException {
        GoldRun goldRun = goldRunService.selecyId(1L);
        if (goldRun==null){
            throw new BusinessException(ExceptionCode.WRONG_SERVER);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功成功");
        jsonResult.setData(goldRun);
        return jsonResult.getDataMap();
    }

}
